package io.zhifei.modules.sys.system.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.zhifei.common.annotation.SysLog;
import io.zhifei.common.utils.ApiResponse;
import io.zhifei.common.utils.DateUtils;
//import io.zhifei.common.utils.ExecelUtil;
import io.zhifei.common.utils.ExecelUitl;
import io.zhifei.modules.sys.system.entity.LogisticsEntity;
import io.zhifei.modules.sys.system.entity.SysLive;
import io.zhifei.modules.sys.system.service.SysLogisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.awt.*;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

/**
 * @ClassNameSysLogisticsController
 * @Description
 * @Author
 * @Date2020/11/25 8:57
 * @Version V1.0
 **/
@CrossOrigin //跨域
@RestController
@RequestMapping("/sys/logistics")
@Api(value = "logistics", description = "物流管理")
public class SysLogisticsController extends AbstractController {

    @Autowired
    private SysLogisticsService sysLogisticsService;

    @SysLog("物流表导入")
    @PostMapping("import")
    @ApiOperation("物流表导入")
    public ApiResponse<Object> logisticsImport(MultipartFile file) {
        try {
            sysLogisticsService.logisticsImport(file);
            return new ApiResponse<>("200", "导入成功！");
        } catch (Exception e) {
            return new ApiResponse<>("500", "导入失败！");
        }
    }

    @GetMapping("logisticsList")
    @ApiOperation("获取物流管理列表")
    public ApiResponse<Object> logisticsList(@ApiParam(name = "page", value = "页码", required = true) @RequestParam Integer page,
                                             @ApiParam(name = "pageSize", value = "每页大小", required = true) @RequestParam Integer pageSize,
                                             @RequestParam(required = false) String hairName,
                                             @RequestParam(required = false) String taskName,
                                             @RequestParam(required = false) String oddNumber) {
        try {
            return new ApiResponse<>(sysLogisticsService.logisticsList(page, pageSize, hairName, taskName, oddNumber));
        } catch (Exception e) {
            return new ApiResponse<>("500", "查询失败！");
        }
    }

    @PostMapping("update")
    @ApiOperation("修改物流管理")
    public ApiResponse<Object> update(@RequestBody LogisticsEntity logisticsEntity) {
        try {
            sysLogisticsService.updateById(logisticsEntity);
            return new ApiResponse<>("200", "修改成功！");
        } catch (Exception e) {
            return new ApiResponse<>("500", "查询失败！");
        }
    }

    @GetMapping("delete")
    @ApiOperation("删除物流管理")
    public ApiResponse<Object> delete(@RequestParam String id) {
        try {
            sysLogisticsService.delete(id);
            return new ApiResponse<>("200", "删除成功！");
        } catch (Exception e) {
            return new ApiResponse<>("500", "删除失败！");
        }
    }
}